﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using static NewlifeCC.Trait;

namespace NewlifeCC
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void new_button_Click(object sender, RoutedEventArgs e)
        {
            Character guy = new Character();
            charBox.Items.Add(guy);
            charBox.SelectedItem = guy;
        }

        private void save_button_Click(object sender, RoutedEventArgs e)
        {


            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName = "NewLifeCharactors"; // Default file name
            dlg.DefaultExt = ".yml"; // Default file extension
            dlg.Filter = "YML documents (.yml)|*.yml"; // Filter files by extension

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;

                String fileText = "";
                foreach (Character guy in charBox.Items)
                {
                    fileText += guy.ToYML() + "\n";
                }
                System.IO.File.WriteAllText(filename, fileText);
            }
        }

        private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            charEdit.DataContext = (Character)(charBox.SelectedItem);
        }

        private void traits_ItemSelectionChanged(object sender, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventArgs e)
        {
            Character guy = (Character)charEdit.DataContext;
            if (e.IsSelected)
            {
                Trait traitToChange = (Trait)e.Item;
                guy.blockedTraits.Remove(traitToChange);
                switch (traitToChange)
                {
                    case HATES_CONDOMS:
                        guy.traits.Remove(CONSCIENTOUS);
                        break;
                    case CONSCIENTOUS:
                        guy.traits.Remove(HATES_CONDOMS);
                        guy.traits.Remove(IMPREGNATOR);
                        break;
                    case HANDSOME:
                        guy.traits.Remove(UGLY);
                        break;
                    case UGLY:
                        guy.traits.Remove(HANDSOME);
                        break;
                    case LIKES_CUTE:
                        guy.traits.Remove(LIKES_SEXY);
                        break;
                    case LIKES_SEXY:
                        guy.traits.Remove(LIKES_CUTE);
                        break;
                    case LIKES_ELEGANT:
                        guy.traits.Remove(LIKES_CASUAL);
                        break;
                    case LIKES_CASUAL:
                        guy.traits.Remove(LIKES_ELEGANT);
                        break;
                    case DULL:
                        guy.traits.Remove(INTERESTING);
                        break;
                    case INTERESTING:
                        guy.traits.Remove(DULL);
                        break;
                    case SLEAZY:
                        guy.traits.Remove(CHARMING);
                        break;
                    case CHARMING:
                        guy.traits.Remove(CRUDE);
                        guy.traits.Remove(SLEAZY);
                        break;
                    case BOASTFUL:
                        guy.traits.Remove(TACITURN);
                        break;
                    case TACITURN:
                        guy.traits.Remove(BOASTFUL);
                        break;
                    case LIKES_BIG_TITS:
                        guy.traits.Remove(LIKES_MED_TITS);
                        guy.traits.Remove(LIKES_SMALL_TITS);
                        break;
                    case LIKES_MED_TITS:
                        guy.traits.Remove(LIKES_BIG_TITS);
                        guy.traits.Remove(LIKES_SMALL_TITS);
                        break;
                    case LIKES_SMALL_TITS:
                        guy.traits.Remove(LIKES_BIG_TITS);
                        guy.traits.Remove(LIKES_MED_TITS);
                        break;
                    case TASTY_SPERM:
                        guy.traits.Remove(NASTY_SPERM);
                        break;
                    case NASTY_SPERM:
                        guy.traits.Remove(TASTY_SPERM);
                        break;
                    case IMPREGNATOR:
                        guy.traits.Remove(LIKES_ORAL);
                        guy.traits.Remove(CONSCIENTOUS);
                        break;
                    case WANTS_KIDS:
                        guy.traits.Remove(DOESNT_WANT_KIDS);
                        break;
                    case DOESNT_WANT_KIDS:
                        guy.traits.Remove(WANTS_KIDS);
                        break;
                    case LIKES_ORAL:
                        guy.traits.Remove(IMPREGNATOR);
                        guy.traits.Remove(PREFERS_SEX);
                        break;
                    case GOOD_DANCER:
                        guy.traits.Remove(BAD_DANCER);
                        break;
                    case BAD_DANCER:
                        guy.traits.Remove(GOOD_DANCER);
                        break;
                    case PREFERS_SEX:
                        guy.traits.Remove(LIKES_ORAL);
                        break;
                }
            }
        }

        private void blockedTraits_ItemSelectionChanged(object sender, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventArgs e)
        {
            Character guy = (Character)charEdit.DataContext;
            if (e.IsSelected)
            {
                Trait traitToChange = (Trait)e.Item;
                guy.traits.Remove(traitToChange);
            }
        }

        private void button_Delete_Click(object sender, RoutedEventArgs e)
        {
            charBox.Items.Remove(charBox.SelectedItem);
        }

        private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
            e.Handled = true;
        }
    }
}
